interface monitorFunType {
    name: string;
    args?: any[];
}
/**
 * 开启模块的监听方法
 * @param monitorModule 需要开启监听的模块
 * @param monitorFun 模块中的方法
 * @return void
 * @example
 * onMonitorFunction('monitorModule',"getFilePath")
 * onMonitorFunction('monitorModule',["getFilePath","consoleTest"])
 * onMonitorFunction('monitorModule',["getFilePath",{name:'monitorModule',args:any}])
 */
export function onMonitorFunction(monitorModule: Record<string, Function>, monitorFun: string | monitorFunType | Array<string | monitorFunType>):void {
    if (typeof monitorModule !== 'object' || monitorModule === null) {
        throw new Error('需要开启的对象不是一个有效的module');
    }
 
    const funcDescriptors = Array.isArray(monitorFun) ? monitorFun : [monitorFun];
 
    funcDescriptors.forEach(descriptor => {
        if (typeof descriptor === 'string') {
            const methodName = descriptor;
            const method = monitorModule[methodName];
 
            if (typeof method === 'function') {
                try {
                    method();
                } catch (error:any) {
                    console.error(`Error calling method ${methodName}: ${error.message}`);
                }
            } else {
                console.warn(`Method ${methodName} does not exist in monitorModule`);
            }
        } else if (typeof descriptor === 'object' && 'name' in descriptor) {
            const { name, args } = descriptor as monitorFunType;
            const method = monitorModule[name];
 
            if (typeof method === 'function') {
                try {
                    method(...(args || []));
                } catch (error:any) {
                    console.error(`Error calling method ${name} with args ${JSON.stringify(args || [])}: ${error.message}`);
                }
            } else {
                console.warn(`Method ${name} does not exist in monitorModule`);
            }
        } else {
            throw new Error('启动的方法描述符必须是字符串或者包含name属性的对象');
        }
    })
}